package com.liam.shradingsphere.shradingsphere.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Mapper
@Component
public interface OrderMapper {

        @Insert("insert into t_order(price,user_id,status) values (#{price},#{userId},#{status})")
        int insertOrderInfo(@Param("price") BigDecimal price, @Param("userId")Long userId, @Param("status")String status);

        @Select("select order_id,price,user_id,status from t_order order by user_id limit 5 ")
        List<Map> queryOrders();

        @Select("select order_id,price,user_id,status from t_order where user_id=#{userId}")
        Map queryByUserId(@Param("userId")Long userId);

        @Select("select order_id,price,user_id,status from t_order where order_id=#{orderId}")
        Map queryByOrderId(@Param("orderId")Long orderId);


        //-------------
        @Select("select user_id,name from t_user where user_id=#{userId}")
        Map queryUserById(@Param("userId")Long userId);

        @Insert("insert into t_user(user_id,name) values (#{userId},#{name})")
        int insertUser(@Param("userId") Long userId,  @Param("name")String name);

        @Select("select user_id,name from t_user where user_id=#{userId}")
        Map queryUser(@Param("userId")Long userId);


}
